package model.playable.unit;
import model.command.*;
import model.playable.*;
import java.util.*;
import model.visibility.*;
import model.mapping.*;
import model.map.*;

public class Melee extends BasicUnit
{
	public Melee(PlayableUser player, List<String> walkableTerrains)
	{
		setWalkableTerrains(walkableTerrains);
		setPlayer(player);
		setIdNumber(-1);
		setUpkeep(1);
		setInfluenceRadius(0);
		setVisibilityRadius(1);
		setCommandQueue(new LinkedList<Command>());
		setCommandsPossibleList(createCommandPossibleList());
		setCurrentPossibleCommandPosition(0);
		setIsInStandBy(false);
		setIsPoweredDown(false);
		setArmyId(-1);
		setRallyPointId(-1);
		setVehicleId(-1);
		setMovementSpeed(1);
		setIsBattleGroup(false);
		setIsReinforcement(false);
		setArmor(10);
		setHealth(40);
		setMaxHealth(40);
		setOffensiveDamage(20);
		setDefensiveDamage(20);
		setIsSoldier(true);
	}
	
	public LinkedList<Command> createCommandPossibleList()
	{
		LinkedList<Command> possibleCommands = new LinkedList<Command>();
		possibleCommands.add(new PowerDown(this));
		possibleCommands.add(new PowerUp(this));
		possibleCommands.add(new Decommission(this));
		possibleCommands.add(new Standby(this));
		possibleCommands.add(new Attack(this));
		possibleCommands.add(new Defend(this));
		possibleCommands.add(new Move(this));
		possibleCommands.add(new Load(this));
		return possibleCommands;
	}

	public void load()
	{
		PlayableMapping map = PlayableMapping.getPlayableMapping();
		GameTile tile = map.getLocationOfUnit(this);
		Vehicle vehicle = map.getFirstAvailableVehicleOn(tile);
		map.removeUnit(this);
		vehicle.loadPassenger(this);
	}
	
	public void incrementHealth(int increment)
	{
		super.incrementHealth(increment);
		if(health <= 0)
			getPlayer().removeMelee(this);
	}
	
	public void decommission()
	{
		getPlayer().removeMelee(this);
	}
	
	public void accept(PlayableVisitor pv)
	{
		pv.visitMelee(this);
	}
	
	public String toString()
	{
		return "Melee";
	}
}